//
//  ContentView.swift
//  emasdemo
//
//  Created by alex on 2024/5/23.
//

import SwiftUI
import Foundation

struct ContentView: View {
    @StateObject private var todoViewModel = TodoViewModel()

    var body: some View {
        NavigationView {
                    List(todoViewModel.todos) { todo in
                        NavigationLink(destination: TodoDetailView(todo: todo)) {
                            Text(todo.title)
                        }
                    }
                    .navigationTitle("Todo List")
                    .onAppear {
                        print("123")
                        todoViewModel.fetchTodos()
                    }
                }
    }

    struct TodoDetailView: View {
        let todo: Todo
        
        var body: some View {
            VStack(alignment: .leading) {
                Text("描述：" + todo.desc)
                    .padding()
                    .multilineTextAlignment(.leading)
                    .navigationTitle(todo.title)
                Text("状态：" + todo.status)
                    .padding()
                    .multilineTextAlignment(.leading)
                Text("优先级：" + todo.desc)
                    .padding()
                    .multilineTextAlignment(.leading)
                Text("期望时间：" + todo.expectTime)
                    .padding()
                    .multilineTextAlignment(.leading)
            }
           
        }
    }
    
}

#Preview {
    ContentView()
}
